package com.kaluli.project.repository.impl;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.kaluli.project.domain.entity.KllOrderLogistics;
import com.kaluli.project.domain.repository.KllOrderLogisticsRepository;
import com.kaluli.system.repository.AbstractRepositorySupport;

@Repository
public class KllOrderLogisticsRepositoryImpl extends AbstractRepositorySupport<KllOrderLogistics> implements KllOrderLogisticsRepository{

	@Override
	protected Class<KllOrderLogistics> getEntityClass() {
		// TODO Auto-generated method stub
		return KllOrderLogistics.class;
	}
	
	
	/**
	 * 同步物流单号
	 * @param orderNumber
	 */
	public void updateExpressNum(String expressNumber, String orderNumber) {

		StringBuffer hql = new StringBuffer("update KllOrderLogistics t set t.expressNumber=? where t.orderNumber=? ");
		Object[] param = { expressNumber, orderNumber };
		this.executeHql(hql.toString(), param);
	}
	
	
	/**
	 * 同步国际段物流信息
	 * @param orderNumber
	 */
	public void updateAbroad(String abroad, String orderNumber) {

		StringBuffer hql = new StringBuffer("update KllOrderLogistics t set t.abroad=? where t.orderNumber=? ");
		Object[] param = { abroad, orderNumber };
		this.executeHql(hql.toString(), param);
	}
	
	/**
	 * 同步国际段物流信息
	 * @param orderNumber
	 */
	public void updateLogistic(String abroad, String orderNumber,int status) {

		StringBuffer hql = new StringBuffer("update KllOrderLogistics t set t.abroad=?,status=?,updatedAt=? where t.orderNumber=? ");
		Object[] param = { abroad,status,new Timestamp(System.currentTimeMillis()),orderNumber };
		this.executeHql(hql.toString(), param);
	}
	
	/**
	 * 
	 * @param orderNumber
	 * @return
	 */
	public KllOrderLogistics findByOrderNumber(String orderNumber) {
		StringBuffer hql=new StringBuffer(" from KllOrderLogistics t  where  t.orderNumber=:orderNumber  ");
		Map<String,Object> params=new HashMap<String, Object>();
		params.put("orderNumber", orderNumber);
		List<KllOrderLogistics> list = findHqlForMap(hql.toString(), params);
		KllOrderLogistics main = null;
		if(list!=null&&list.size()>0){
			main = list.get(0);
		}
		return main;
	}

}
